package com.youlai.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.system.common.result.PageResult;
import com.youlai.system.common.result.Result;
import com.youlai.system.mapper.AirportMapper;
import com.youlai.system.model.entity.AirPlane;
import com.youlai.system.model.entity.Airport;
import com.youlai.system.model.query.AirPlaneQuery;
import com.youlai.system.model.vo.AirPlaneVO;
import com.youlai.system.service.AirPlaneService;
import com.youlai.system.service.AirSeatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0
 * @Author Ricardo
 * @Date 2024/11/25 9:05
 * @注释
 */

@Tag(name = "19.航班信息接口")
@RestController
@RequestMapping("/api/v1/pl2")
@RequiredArgsConstructor
@Slf4j
public class AirPla2Controller {


    final AirPlaneService airPlaneService;

    @Autowired
    private AirportMapper airportMapper;

    @Operation(summary = "获取空闲飞机信息列表")
    @GetMapping("/page")
    PageResult<AirPlaneVO> getPlaneNotFly(@ParameterObject AirPlaneQuery queryParams){
        log.info("请求空闲飞机信息");
        log.info("完整接收到的 queryParams: {}", queryParams);

        log.info("查询的页数为"+queryParams.getPageNum());
        IPage<AirPlaneVO> result = airPlaneService.getPlaneNotFly(queryParams);
        System.out.println("查询结果"+result);
        return PageResult.success(result);
    }


    @GetMapping("/select")
    Result<AirPlane> getPlane(@RequestParam long planeId){
        AirPlane airPlane = airPlaneService.getPlaneById(planeId);
        log.info("后端请求飞机信息");
        return Result.success(airPlane);
    }

    @GetMapping("/select/airports")
    Result<List<Airport>> getAirports(){
        log.info("后端请求机场信息");
        return Result.success(airportMapper.getAirports());
    }


}
